package top.wshape1.rpc.loadbalance;

import top.wshape1.rpc.common.entity.ServiceMeta;

import java.util.List;

/**
 * @author Wshape1
 * @version 1.0
 * @description 负载均衡抽象类
 * @since 2024-02-10
 */

public abstract class AbstractLoadBalance implements LoadBalance {

    @Override
    public ServiceMeta select(List<ServiceMeta> serviceMetas) {
        if (serviceMetas == null || serviceMetas.isEmpty())
            return null;
        if (serviceMetas.size() == 1)
            return serviceMetas.get(0);
        return doSelect(serviceMetas);
    }

    protected abstract ServiceMeta doSelect(List<ServiceMeta> serviceMetas);

}
